package com.ruoyi.apiserver.services;

import com.ruoyi.apiserver.config.RabbitMQConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class RabbitMQProducerService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送简单字符串消息
     * @param message 消息内容
     */
    public void sendSimpleMessage(String message) {
        rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_NAME, RabbitMQConfig.ROUTING_KEY, message);
    }

    /**
     * 发送Map类型消息
     * @param message 消息内容
     */
    public void sendMessageWithMap(Map<String, Object> message) {
        rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_NAME, RabbitMQConfig.ROUTING_KEY, message);
    }

    /**
     * 发送带特定路由键的消息
     * @param routingKey 路由键
     * @param message 消息内容
     */
    public void sendMessageWithRoutingKey(String routingKey, Object message) {
        rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_NAME, routingKey, message);
    }
}